From 942df078b670ae2ed33dff3f77ac997fa4ca377f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Mon, 10 Nov 2025 23:19:31 +0100 Subject: [PATCH] odhcpd: rename dhcpv6_lease->clid[_data|_len] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The option is called clientid, but the option carries a DUID. So what we're storing is a DUID, not a CLID. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/306 Signed-off-by: Álvaro Fernández Rojas --- src/dhcpv6-ia.c | 46 +++++++++++++++++++++++----------------------- src/odhcpd.h | 6 +++--- src/statefiles.c | 2 +- src/ubus.c | 4 ++-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 3af3e42..209c367 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -176,7 +176,7 @@ static int send_reconf(struct dhcpv6_lease *assign) uint8_t data[DUID_MAX_LEN]; } _packed clientid = { .code = htons(DHCPV6_OPT_CLIENTID), - .len = htons(assign->clid_len), + .len = htons(assign->duid_len), .data = { 0 }, }; struct { @@ -209,7 +209,7 @@ static int send_reconf(struct dhcpv6_lease *assign) serverid.len = htons(sizeof(duid_ll_hdr) + ETH_ALEN); } - memcpy(clientid.data, assign->clid_data, assign->clid_len); + memcpy(clientid.data, assign->duid, assign->duid_len); struct iovec iov[IOV_TOTAL] = { [IOV_HDR] = { &hdr, sizeof(hdr) }, @@ -426,8 +426,8 @@ static bool assign_na(struct interface *iface, struct dhcpv6_lease *a) /* Pick a starting point, using the last bytes of the DUID as seed... */ memcpy(xsubi, - a->clid_data + (a->clid_len > sizeof(xsubi) ? a->clid_len - sizeof(xsubi) : 0), - min(a->clid_len, sizeof(xsubi))); + a->duid + (a->duid_len > sizeof(xsubi) ? a->duid_len - sizeof(xsubi) : 0), + min(a->duid_len, sizeof(xsubi))); try = ((uint64_t)jrand48(xsubi) << 32) | (jrand48(xsubi) & UINT32_MAX); try = pool_start + try % pool_size; @@ -473,8 +473,8 @@ static void handle_addrlist_change(struct netevent_handler_info *info) set_border_assignment_size(iface, border); list_for_each_entry_safe(c, d, &iface->ia_assignments, head) { - if (c->clid_len == 0 || - !(c->flags & OAF_DHCPV6_PD) || + if (c->duid_len == 0 || + !(c->flags & OAF_DHCPV6_PD) || (!INFINITE_VALID(c->valid_until) && c->valid_until < now)) continue; @@ -490,8 +490,8 @@ static void handle_addrlist_change(struct netevent_handler_info *info) /* Leave all other assignments of that client alone */ list_for_each_entry(a, &iface->ia_assignments, head) - if (a != c && a->clid_len == c->clid_len && - !memcmp(a->clid_data, c->clid_data, a->clid_len)) + if (a != c && a->duid_len == c->duid_len && + !memcmp(a->duid, c->duid, a->duid_len)) a->fr_cnt = INT_MAX; } } @@ -548,7 +548,7 @@ static void valid_until_cb(struct uloop_timeout *event) continue; list_for_each_entry_safe(a, n, &iface->ia_assignments, head) { - if (a->clid_len > 0 && !INFINITE_VALID(a->valid_until) && a->valid_until < now) + if (a->duid_len > 0 && !INFINITE_VALID(a->valid_until) && a->valid_until < now) dhcpv6_free_lease(a); } } @@ -942,17 +942,17 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac struct dhcpv6_lease *first = NULL; const struct dhcpv6_client_header *hdr = data; time_t now = odhcpd_time(); - uint16_t otype, olen, clid_len = 0; + uint16_t otype, olen, duid_len = 0; uint8_t *start = (uint8_t *)&hdr[1], *odata; - uint8_t *clid_data = NULL, mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + uint8_t *duid = NULL, mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; size_t hostname_len = 0, response_len = 0; bool notonlink = false, rapid_commit = false, accept_reconf = false; char duidbuf[DUID_HEXSTRLEN], hostname[256]; dhcpv6_for_each_option(start, end, otype, olen, odata) { if (otype == DHCPV6_OPT_CLIENTID) { - clid_data = odata; - clid_len = olen; + duid = odata; + duid_len = olen; if (olen == 14 && odata[0] == 0 && odata[1] == 1) memcpy(mac, &odata[8], sizeof(mac)); @@ -974,7 +974,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac rapid_commit = true; } - if (!clid_data || !clid_len || clid_len > DUID_MAX_LEN) + if (!duid || duid_len < DUID_MIN_LEN || duid_len > DUID_MAX_LEN) goto out; dhcpv6_for_each_option(start, end, otype, olen, odata) { @@ -990,7 +990,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac uint32_t reqhint = 0; struct lease_cfg *lease_cfg; - lease_cfg = config_find_lease_cfg_by_duid_and_iaid(clid_data, clid_len, ntohl(ia->iaid)); + lease_cfg = config_find_lease_cfg_by_duid_and_iaid(duid, duid_len, ntohl(ia->iaid)); if (!lease_cfg) lease_cfg = config_find_lease_cfg_by_mac(mac); @@ -1068,8 +1068,8 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac continue; /* Does the DUID match? */ - if (c->clid_len != clid_len || memcmp(c->clid_data, clid_data, clid_len)) - continue; + if (c->duid_len != duid_len || memcmp(c->duid, duid, duid_len)) + continue; /* Does the IAID match? */ if (c->iaid != ia->iaid) { @@ -1092,10 +1092,10 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac if (lease_cfg->duids[i].iaid_set && lease_cfg->duids[i].iaid != htonl(ia->iaid)) continue; - if (lease_cfg->duids[i].len != clid_len) + if (lease_cfg->duids[i].len != duid_len) continue; - if (memcmp(lease_cfg->duids[i].id, clid_data, clid_len)) + if (memcmp(lease_cfg->duids[i].id, duid, duid_len)) continue; /* @@ -1138,11 +1138,11 @@ proceed: if ((!iface->no_dynamic_dhcp || (lease_cfg && is_na)) && (iface->dhcpv6_pd || iface->dhcpv6_na)) { /* Create new binding */ - a = dhcpv6_alloc_lease(clid_len); + a = dhcpv6_alloc_lease(duid_len); if (a) { - a->clid_len = clid_len; - memcpy(a->clid_data, clid_data, clid_len); + a->duid_len = duid_len; + memcpy(a->duid, duid, duid_len); a->iaid = ia->iaid; a->length = reqlen; a->peer = *addr; @@ -1275,7 +1275,7 @@ proceed: a->flags &= ~OAF_BOUND; if (!(a->flags & OAF_STATIC) || a->lease_cfg->hostid != a->assigned_host_id) { - memset(a->clid_data, 0, a->clid_len); + memset(a->duid, 0, a->duid_len); a->valid_until = now + 3600; /* Block address for 1h */ } else a->valid_until = now - 1; diff --git a/src/odhcpd.h b/src/odhcpd.h index fbbba1a..d986080 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -278,15 +278,15 @@ struct dhcpv6_lease { uint64_t assigned_host_id; uint32_t assigned_subnet_id; }; - uint32_t iaid; uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD unsigned int flags; uint32_t leasetime; char *hostname; - uint16_t clid_len; - uint8_t clid_data[]; + uint32_t iaid; + uint16_t duid_len; + uint8_t duid[]; }; /* This corresponds to a UCI host section, i.e. a static lease cfg */ diff --git a/src/statefiles.c b/src/statefiles.c index 4258cbf..65920d2 100644 --- a/src/statefiles.c +++ b/src/statefiles.c @@ -192,7 +192,7 @@ static void statefiles_write_state6(struct write_ctxt *ctxt, struct dhcpv6_lease if (!ctxt->fp) return; - odhcpd_hexlify(duidbuf, lease->clid_data, lease->clid_len); + odhcpd_hexlify(duidbuf, lease->duid, lease->duid_len); /* # [ ...] */ fprintf(ctxt->fp, diff --git a/src/ubus.c b/src/ubus.c index 51c4708..ca15d37 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -130,9 +130,9 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct continue; void *m, *l = blobmsg_open_table(&b, NULL); - char *buf = blobmsg_alloc_string_buffer(&b, "duid", 264); + char *buf = blobmsg_alloc_string_buffer(&b, "duid", DUID_HEXSTRLEN); - odhcpd_hexlify(buf, a->clid_data, a->clid_len); + odhcpd_hexlify(buf, a->duid, a->duid_len); blobmsg_add_string_buffer(&b); blobmsg_add_u32(&b, "iaid", ntohl(a->iaid)); -- 2.30.2